Skip to content

Add guardrails to block dangerous shell commands#30

Merged
joone merged 4 commits intomainfrom
copilot/add-guardrails-feature
Feb 16, 2026
Merged

Add guardrails to block dangerous shell commands#30
joone merged 4 commits intomainfrom
copilot/add-guardrails-feature

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 16, 2026

Loz executes LLM-generated shell commands without validation. This adds a guardrails layer to prevent execution of destructive commands.

Changes

New guardrails module (src/guardrails/index.ts)

  • enforceGuardrails() function checks commands against denylist before execution
  • Blocks: rm -rf /, shutdown, reboot, fork bomb, mkfs, dd if=
  • Includes bypass variants: rm -rf/*, rm -rf /.
  • Case-insensitive substring matching with pre-computed patterns

Integration (src/loz.ts)

  • Guardrails enforced before each command execution:
for (const cmd of commands) {
  try {
    enforceGuardrails(cmd, true);  // Blocks dangerous commands
    await runCommand(cmd);
  } catch (error) {
    console.error(error.message);  // "Command blocked by guardrails: rm -rf /"
  }
}

Tests (test/guardrails.test.ts)

  • Validates dangerous command blocking
  • Validates safe command pass-through
  • Covers bypass attempts

Limitations

Substring matching can produce false positives (e.g., filename containing "shutdown") and can be bypassed with command variations not in the denylist. Documented for future improvement with command structure parsing or allowlist approach.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits February 16, 2026 10:41
Co-authored-by: joone <1979160+joone@users.noreply.github.com>
Co-authored-by: joone <1979160+joone@users.noreply.github.com>
Co-authored-by: joone <1979160+joone@users.noreply.github.com>
Copilot AI changed the title [WIP] Add safety feature for shell allow/deny checks Add guardrails to block dangerous shell commands Feb 16, 2026
Copilot AI requested a review from joone February 16, 2026 10:46
@joone joone marked this pull request as ready for review February 16, 2026 19:35
@joone joone merged commit bdb5bb2 into main Feb 16, 2026
0 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants